if __name__ == '__main__':
    from rgeSystem import injectMain, SAVE_DIR
    from PyQt4.QtCore import *
    from PyQt4.QtGui import *
    from PyQt4.QtOpenGL import *

    from rgeJson import loadString, jsonload
    import os

    fieldtemp = ["English"]
    app = QApplication(['RGG in Space'])

    try:
        js = jsonload(os.path.join(SAVE_DIR, "lang_settings.rgs"))
        fieldtemp[0] = loadString('lang.language', js.get('language'))
    except:
        print "no language settings detected"
        pass

    if fieldtemp[0] != "English":
        transfile = ""
        if fieldtemp[0] == "Japanese":
            transfile = "rge_py_ja"
        if fieldtemp[0] == "Dutch":
            transfile = "rge_py_nl"
        if fieldtemp[0] == "German":
            transfile = "rge_py_de"

        trans = QTranslator()
        if not trans.load(transfile):
            print transfile + "not found"
        app.installTranslator(trans)

    qgf = QGLFormat.defaultFormat()
    qgf.setSampleBuffers(True)
    QGLFormat.setDefaultFormat(qgf)

    main = injectMain()

    import rgeSystem, rgeViews, rgeEvent

    # Initialize view state.
    s = rgeViews._state
    s.initialize(app)

    # EVENT WIRING
    # amounts to configuration

    # mouse events
    main.glwidget.mouseMoveSignal.connect(rgeEvent.mouseMoveEvent)
    main.glwidget.mousePressSignal.connect(rgeEvent.mousePressEvent)
    main.glwidget.mouseReleaseSignal.connect(rgeEvent.mouseReleaseEvent)

    # tool widget

    # menu items
    s.menu.newModuleAct.triggered.connect(rgeViews.newModule)
    s.menu.loadModuleAct.triggered.connect(rgeViews.openModule)


    s.menu.moduleModeAct.triggered.connect(rgeViews.setModuleMode)
    s.menu.tilesetModeAct.triggered.connect(rgeViews.setTilesetMode)
    s.menu.sceneModeAct.triggered.connect(rgeViews.setSceneMode)
    s.menu.spriteModeAct.triggered.connect(rgeViews.setSpriteMode)
    s.menu.actorModeAct.triggered.connect(rgeViews.setActorMode)
    #s.menu.newMapAct.triggered.connect(rgeViews.newMap)
    #s.menu.loadMapAct.triggered.connect(rgeViews.loadMap)
    #s.menu.saveSessAct.triggered.connect(rgeViews.saveSession)
    #s.menu.loadSessAct.triggered.connect(rgeViews.loadSession)
    #s.menu.saveMapAct.triggered.connect(rgeViews.saveMap)
    #s.menu.closeMapAct.triggered.connect(rgeViews.closeAllMaps)
    #s.menu.gfxSettingsAct.triggered.connect(rgeViews.configureGfx)
    #s.menu.thicknessMenu.triggered.connect(rgeViews.setThickness)
    #s.menu.colourMenu.triggered.connect(rgeViews.setLineColour)
    #s.menu.langMenu.triggered.connect(rgeViews.setLanguage)

    # Start execution
    main.show()
    app.exec_()
